package com.xsl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {
        ArrayList<String> arrayList=new ArrayList<>();
        arrayList.add("zhangsan");
        arrayList.add("zhangsan");
        ArrayList<String> newList = new ArrayList<>(new HashSet<>(arrayList));
        System.out.println(newList);
        System.out.println("---------迭代器方式-----------");
        HashSet<String> hashSet =new HashSet<>();
        hashSet.add("lisi1");
        hashSet.add("lisi2");
        hashSet.add("lisi3");
        hashSet.add("lisi4");
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

        System.out.println("-----------增强for------");
        for(String s :hashSet){
            System.out.println(s);
        }
        System.out.println("--------匿名内部类-----------");
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("--------Lambda表达式------------");
        hashSet.forEach(s-> System.out.println(s));
        System.out.println("-------------方法引用-----------------");
        hashSet.forEach(System.out::println);

        Student student =new Student("zhangsan",18);
        System.out.println(student.toString());

    }
}
